<?php
session_start();
require_once("include/ui.php");
require_once ("model/m_admin.php");

date_default_timezone_set('UTC');

if (!(isset($_SESSION['adminid']))){
        echo "<meta http-equiv = refresh ; content = '0 ; url = index.php'>";
}
  $val=array();
  $ad = new M_admin();
if (  ( $_POST['mode']=='add' ) ){
    $title=$_POST['txtTitle'];
    if ( get_magic_quotes_gpc() )
        $postedValue = htmlspecialchars( stripslashes( $_POST['editor1'] ) ) ;
    else
        $postedValue = htmlspecialchars( $_POST['editor1'] ) ;
    
  
    $ad->addNews($title, $postedValue);
     echo "<meta http-equiv = refresh ; content = '0 ; url = _news.php'>";
} 
else if ($_POST['mode']=='edit'){
    
      $title=$_POST['txtTitle'];
    if ( get_magic_quotes_gpc() )
        $postedValue = htmlspecialchars( stripslashes( $_POST['editor1'] ) ) ;
    else
        $postedValue = htmlspecialchars( $_POST['editor1'] ) ;
    
    $id=$_POST['i']; 
    $ad->editNews($id, $title, $postedValue);
    echo "<meta http-equiv = refresh ; content = '0 ; url = _news.php'>";
    
}
if ($_GET['m']=='edit'){
    $id = $_GET['i'];
    $val=$ad->getNewsDetail($id);
    
    
}
// show header
echo headerPage("CD Hidef-Backend");
?>

 <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
 <script>
     function checkInput(){
         if (document.getElementById("txtTitle").value==""){
             alert('กรุณากรอก หัวข้อ');
         return false;
        }   
     }
 </script>
<style>
    a:hover{
        text-decoration:underline;
    }
    .sort{
        cursor:pointer;
    }
</style>
<FORM id="Act" action="_news_details.php" method="post"> 

<INPUT type=hidden value="<?php echo isset($_GET['m'])?$_GET['m']:'add';?>" id="mode" name="mode"> 
<INPUT type=hidden value="<?php echo $_GET['i'];?>" id="i" name="i">

<table width="1026" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="10" id='leftboder' style='border-left:1px solid #ccc;'>&nbsp;</td>
    <td width="1004" valign="top">
        <div class="content-box">
            <div Class="toolbar-box">   
                <div class="t">
                    <div class="t">
                        <div class="t"></div>
                    </div>
                 </div>
                 <div class="m">
                    <div class="toolbar">
                        <table class="toolbar">
                        <tr>
                            <td>
 
                            </td>
                                <td>
                                   <a href="_news.php" title="Print" id="btnPrint">
                                <span class="icon_back"></span>Back
                                </a>
                            </td>
                        </tr>
                        </table>
                    </div>
                      <div class="header" style="background-image: url(images/home_article.png);">
                     
                            News-Detail
                       
                      </div>
                <div class="clr"></div>
                 </div>
                 <div class="b">
                    <div class="b">
                        <div class="b"></div>
                    </div>
                 </div>
            </div>
               <div id="element-box">
                <div class="t">
                    <div class="t">
                        <div class="t"></div>
                    </div>
                </div>
                <div class="m">
                    <table width="100%" id='searchdata' border="0">
 
                        
                       <tr>
                            <td width="15%" class="fontSearch" style="padding-left:20;padding-top:5px;">
                           &nbsp;&nbsp;&nbsp; หัวข้อ : 
                            </td>
                            <td  align=left style="padding-top:5px;">
                                <input type="text" name="txtTitle"  id="txtTitle" value="<?php echo $val['title'];?>"  style='width:80%;' />
                            </td>
                             
                         </tr>                       
                       
                       <tr>
                            <td width="15%" class="fontSearch" style="padding-left:20;padding-top:5px;">
                           &nbsp;&nbsp;&nbsp; รายละเอียด : 
                            </td>
                            <td  align=left style="padding-top:5px;">
                                     <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10" style="visibility: hidden; display: none; ">
                                         <?php
 
                                                   echo ( stripslashes( $val['description'] ) ) ;
                                                
                                         ?>
                                         
                                     </textarea>
                            </td>
                             
                         </tr>                       
                       
                         <tr>
                            <td colspan="2">
                                <input type="submit" onclick="return checkInput();" value="Submit">
                            </td>
                         </tr>
                    </table>
                    
                  <div class="clr"></div>
                </div>
                 <div class="b"><div class="b"><div class="b"></div></div></div>
                 <div class="clr"></div>
                </div> <!-- elementbox-->
        </div>
    </td>
    <td width="10" id='rightboder'  style="border-right:1px solid #ccc;">&nbsp;</td>
  </tr>
</table>
 </FORM>
 
 
<?php echo footer();?>